// 函数组合演示
function compose(f, g) {
  return function (value) {
    return f(g(value));
  };
}

function reverse(array) {
  return array.reverse();
}

function first(array) {
  return array[0];
}

const last = compose(first, reverse);

console.log(last([1, 2, 3, 4]));

// 以下是个人对函数组合函数的猜想
/**
function compose(...funcs) {
  return function () {
    const last = funcs.pop();
    return funcs.reduceRight(
      (prev, current, index) => current(prev),
      last(...arguments)
    );
  };
}

function sum(...args) {
  return args.reduce((prev, current) => prev + current, 0);
}

function pow(x) {
  return Math.pow(x, 2);
}

const sumPow = compose(pow, sum);

const res = sumPow(1, 2, 3, 4);
console.log(res);
*/
